<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>球队列表</title>
    
	<style type="text/css">
	#mytable {
	    width: 40%;
	    padding: 0;
	    margin: 0 auto;
	    text-algin: center;
	}
	caption {
	    padding: 0 0 5px 0;
	    font: italic 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
	    text-align: center;
	}
	th {
	    font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
	    color: #4f6b72;
	    border-right: 1px solid #C1DAD7;
	    border-bottom: 1px solid #C1DAD7;
	    border-top: 1px solid #C1DAD7;
	    letter-spacing: 2px;
	    text-transform: uppercase;
	    text-align: left;
	    padding: 6px 6px 6px 12px;
	    background-color: #CAE8EA;
	}
	td {
	    border-right: 1px solid #C1DAD7;
	    border-bottom: 1px solid #C1DAD7;
	    background: #fff;
	    font-size:11px;
	    padding: 6px 6px 6px 12px;
	    color: #4f6b72;
	}
	td.alt {
	    background: #F5FAFA;
	    color: #797268;
	}
	/*---------for IE 5.x bug*/
	html>body td{ font-size:11px;}
	</style>
</head>
<body>
<?php
require dirname(__FILE__) . '/checkuser.php';
require dirname(dirname(__FILE__)) . '/include/conf.php';
require dirname(dirname(__FILE__)) . '/include/database.php';

$page = isset($_GET['page']) ? (int) $_GET['page'] : 1;
$page = ($page > 0) ? $page : 1;
$page_size = 20;
$offset = ($page - 1) * $page_size;

$db = db_touzhu();

$sql_team_188 = 'select 188bet_id, team, add_time from teams where `from`=2 order by bet365_id desc ';
$sql_team_188 .= "limit {$offset}, {$page_size}";
$teams_188bet = $db->query($sql_team_188);

if (!empty($teams_188bet)){
	$teams = $team_188_ids = array();
	foreach ($teams_188bet as $_team){
		$team_188_ids[] = $_team['188bet_id'];
		$teams[] = array(
			'id' => $_team['188bet_id'],
			'188bet' => $_team['team']
		);
	}

	if (!empty($team_188_ids)){
		$where = 'and bet365_id in(' . implode(',', $team_188_ids) . ')';
		$sql_team_365 = 'select bet365_id, team, add_time from teams where `from`=1 ';
		$sql_team_365 .= "{$where}";
		$teams_bet365 = $db->query($sql_team_365);
		
		if (!empty($teams_bet365)){
			$team_365_arr = array();
			foreach ($teams_bet365 as $_team){
				$team_365_arr[$_team['bet365_id']] = $_team['team'];
			}
			foreach ($teams as &$_team){
				if (isset($team_365_arr[$_team['id']])) {
					$_team['bet365'] = $team_365_arr[$_team['id']];
				}
			}
		}
	}
}

?>
<table id="mytable" cellspacing="0">
<caption>比赛列表</caption>
  <tr>
  	<th>id</th>
  	<th>bet365</th>
	<th>188bet</th>
  </tr>
<?php
if (is_array($teams) && !empty($teams)){
	$counter = 1;
	foreach ($teams as $team){
		echo '<tr>';
		echo '<td',  ($counter % 2 == 0) ? ' class="alt"' : '', '>', $team['id'], '</td>';
		echo '<td',  ($counter % 2 == 0) ? ' class="alt"' : '', '>', isset($team['bet365']) ? $team['bet365'] : '', '</td>';
		echo '<td',  ($counter % 2 == 0) ? ' class="alt"' : '', '>', $team['188bet'], '</td>';
		echo '</tr>';
		$counter ++;
	}
}
?>

<tr><td colspan="3" align="right">
	<a href="?page=1">第一页</a> | 
	<a href="?page=<?php echo ($page == 1) ? $page : $page - 1?>">上一页</a> | 
	<a href="?page=<?php echo $page + 1?>">下一页</a>
</td></tr>
</table>
</body>
</html>